package com.mjl.shops.activity;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;

import com.mjl.shops.R;
import com.mjl.shops.adapter.CollectionAdapter;
import com.mjl.shops.base.BaseActivity;
import com.mjl.shops.base.BaseDate;
import com.mjl.shops.bean.CollectionBean;
import com.mjl.shops.utils.CommUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MineCollectionActivity extends BaseActivity {

    private boolean isEditor = false;

    private List<CollectionBean> collectionBeans = new ArrayList<>();

    private CollectionAdapter adapter;

    @BindView(R.id.bottom_rl)
    RelativeLayout bottom_rl;

    @BindView(R.id.collection_recycler)
    RecyclerView collection_recycler;

    @Override
    protected void setContentViewBefore() {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    @Override
    protected int getViews() {
        return R.layout.activity_mine_collection;
    }

    @Override
    protected void setViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void setDate() {
        collectionBeans.clear();
        collectionBeans.addAll(BaseDate.getCollectionBeans());
        adapter = new CollectionAdapter(R.layout.item_collection_layout,collectionBeans);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this,2);
        collection_recycler.setLayoutManager(gridLayoutManager);
        collection_recycler.setAdapter(adapter);
    }

    @Override
    protected String getStateColor() {
        return CommUtils.color_05000000;
    }

    @Override
    protected int getStetaBackgroundStyle() {
        return 1;
    }

    @OnClick({R.id.icon_back, R.id.editor_tv})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.icon_back:
                finish();
                break;
            case R.id.editor_tv:
                if (!isEditor) {
                    isEditor = true;
                    bottom_rl.setVisibility(View.VISIBLE);
                    adapter.setShowSelect(true);
                } else {
                    isEditor = false;
                    bottom_rl.setVisibility(View.GONE);
                    adapter.setShowSelect(false);
                }
                adapter.notifyDataSetChanged();
                break;
            default:
                break;
        }
    }

    public static void StartIntent(Context contexts){
        Intent intent = new Intent(contexts,MineCollectionActivity.class);
        contexts.startActivity(intent);
    }
}
